<?php Block::put('breadcrumb') ?>
<ul>
    <li><a href="<?= Backend::url('summer/hjd/ruleconfig') ?>">规则设置</a></li>
    <li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<div class="layout-cell layout-container" id="layout-body">
    <div class="layout-relative">
        <div class="layout">
            <!-- Content -->
            <div class="layout-row">
                <div class="layout-row">
                    <!-- Primary Tabs -->
                    <div class="layout-row">
                        <div id="Form-primaryTabs" class="control-tabs primary-tabs layout has-tabs" data-control="tab">
                            <div class="layout-row min-size">
                                <ul class="nav nav-tabs" data-disposable="">
                                    <li class="active ">
                                        <a href="#primarytab-1" data-target="#tab1" data-toggle="tab" title="奖金规则">
                                            <span class="title">
                                                <span>
                                                    奖金规则
                                                </span>
                                            </span>
                                        </a>
                                        <span class="tab-close"><i>×</i></span>
                                    </li>
                                    <li class="">
                                        <a href="#primarytab-2" data-target="#tab2" data-toggle="tab" title="充值规则">
                                            <span class="title">
                                                <span>
                                                    充值规则
                                                </span>
                                            </span>
                                        </a>
                                        <span class="tab-close"><i>×</i></span>
                                    </li>
                                    <li class="">
                                        <a href="#primarytab-3" data-target="#tab3" data-toggle="tab" title="提现规则">
                                            <span class="title">
                                                <span>
                                                    提现规则
                                                </span>
                                            </span>
                                        </a>
                                        <span class="tab-close"><i>×</i></span>
                                    </li>
                                    <li class="">
                                        <a href="#primarytab-4" data-target="#tab4" data-toggle="tab" title="转账规则">
                                            <span class="title">
                                                <span>
                                                    转账规则
                                                </span>
                                            </span>
                                        </a>
                                        <span class="tab-close"><i>×</i></span>
                                    </li>
                                </ul>
                            </div>
                            <div class="tab-content layout-row">
                                <div class="tab-pane   active layout-cell" id="tab1">
                                    <?= $this->widget->rulebonus->render() ?>
                                </div>
                                <div class="tab-pane   layout-cell" id="tab2">
                                    <?= $this->widget->rulerg->render() ?>
                                </div>
                                <div class="tab-pane   layout-cell" id="tab3">
                                    <?= $this->widget->rulewd->render() ?>
                                </div>
                                <div class="tab-pane   layout-cell" id="tab4">
                                    <?= $this->widget->ruletf->render() ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>
</div>

<input type="hidden" id="rule_quick_url" value="<?= Backend::url('summer/hjd/ruleconfig/onQuickedit') ?>">
<script type="text/javascript">
    $(function(){
        var rule_quick_url= $("#rule_quick_url").val();
        // 快速编辑的url提交地址
        $.fn.editable.defaults.url = rule_quick_url;
        // 样式，行内还是弹出 inline、popup 也可单独设置
        // $.fn.editable.defaults.mode = 'inline';
        // 值为空时显示的信息
        $.fn.editable.defaults.emptytext = '空值';
        var ajaxOptions=[];
        ajaxOptions.headers= {
            'X-WINTER-REQUEST-HANDLER': "onQuickedit"
        };
        $.fn.editable.defaults.ajaxOptions = ajaxOptions;
        // 提交时的额外参数
        $.fn.editable.defaults.params = function (params) {
            params.table    = $(this).data('table') || '';
            params.type     = $(this).data('type') || '';
            return params;
        };
        // 提交成功时的回调函数
        $.fn.editable.defaults.success = function (res) {
            if (res.status) {
                $.oc.alert(res.msg);
            } else {
                $.oc.alert(res.msg);
                return false;
            }
        };
        // 提交失败时的回调函数
        $.fn.editable.defaults.error = function(res) {
            $.oc.alert('提交失败！');
        };

        // 可编辑单行文本
        $('.text-edit').editable();
        // 可编辑多行文本
        $('.textarea-edit').editable({
            showbuttons: 'bottom'
        });
        // 下拉编辑
        $('.select-edit').editable();
        $('.select2-edit').editable({
            select2: {
                multiple: true,
                tokenSeparators: [',', ' ']
            }
        });
        // 日期时间
        $('.combodate-edit').editable({
            combodate: {
                maxYear: 2999,
                minuteStep: 1
            }
        });

        //开关
        $('.switch input:checkbox').on('click', function () {
            var $switch = $(this);
            var $data = {
                value: $switch.prop('checked'),
                table: $switch.data('table') || '',
                name: $switch.data('field') || '',
                type: 'switch',
                pk: $switch.data('id') || '',
            };
            $.ajax({
                type: "POST",
                url: rule_quick_url,
                headers: {
                    'X-WINTER-REQUEST-HANDLER': "onQuickedit"
                },
                data:$data,
                success: function(res) {
                    if (res.status) {
                        $.oc.alert(res.msg);
                    }else{
                        $.oc.alert(res.msg);
                        $switch.prop('checked', !$data.status);
                        return false;
                    }
                },
            });
        });
        $('.weeks-edit').editable({
            //因为数据量大，看不到确认按钮
            mode:'inline',
            source: <?= $week_json ?>
        });
        $('.days-edit').editable({
            //因为数据量大，看不到确认按钮
            mode:'inline',
            source: <?= $day_json ?>
        });
    });
</script>